package org.blackcat.web;

import org.blackcat.core.annotation.Login;
import org.blackcat.domain.BloodPressure;
import org.blackcat.domain.common.MsgResponse;
import org.blackcat.domain.enums.UserEnum;
import org.blackcat.service.BloodPressureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 詹泽
 * @date 2017/2/23
 */
@RestController
@RequestMapping("/bloodPressure")
public class BloodPressureController {

    @Autowired
    private BloodPressureService bloodPressureService;

    @RequestMapping(value = "",method = RequestMethod.PUT)
    @Login
    MsgResponse<Object> addBloodPressure(BloodPressure bloodPressure, HttpServletRequest request) throws Exception{
        String token = (String) request.getAttribute(UserEnum.USER_REQUEST_TOKEN.getValue());
        return bloodPressureService.addBloodPressure(bloodPressure,token);
    };

    @RequestMapping(value="/{date}/{status}",method = RequestMethod.GET)
    @Login
    MsgResponse<List<BloodPressure>> listBloodPressure(@PathVariable String date,@PathVariable int status,HttpServletRequest request) throws Exception{
        String token = (String) request.getAttribute(UserEnum.USER_REQUEST_TOKEN.getValue());
        return bloodPressureService.listBloodPressure(token,date,status);
    };

}
